var fs = require('fs');
var path = require('path');
var glob = require("glob")
var _time = new Date().getTime();
glob.sync(path.resolve(__dirname, '../views/*.html')).map((filepath, i) => {
  fs.readFile(filepath, 'utf8', function (err, files) {
    var result = files.replace(/href=["'][\w\/\.-]*\.css.*?["']/g, uri => {
      // if (filepath.indexOf("workbench") >= 0) {
      //   console.log(uri);
      // }
      // 拿到静态路径
      var str = uri.replace("href=", "").replace(/["']/g, "");
      var uris = str.split('?');
      let _uri = `href="${uris[0]}?z=${_time}"`;
      return _uri;
    });
    result = result.replace(/src=["'][\w\/\.-]*\.js.*?["']/g, uri => {
      // 拿到静态路径
      var str = uri.replace("src=", "").replace(/["']/g, "");
      var uris = str.split('?');
      let _uri = `src="${uris[0]}?z=${_time}"`;
      return _uri;
    });
    fs.writeFile(filepath, result, 'utf8', function (err) {
      if (err) return console.log(err);
    });
  });
});